import { StorehouseService } from './../../../../../@core/services/storehouse/storehouse.service';
import { Component, Input, ViewChild } from '@angular/core';
import { DataTableComponent, TableWidthConfig, DialogService } from 'ng-devui';
import { SharedMethodService } from 'src/app/@core/services/Sharedmethod/shared-method.service';
import { JobOrderService } from 'src/app/@core/services/jobOrder/job-order.service';
import { GetPartsComponent } from './get-parts/get-parts.component';

@Component({
  selector: 'app-select-part',
  templateUrl: './select-part.component.html',
  styleUrls: ['./select-part.component.scss'],
})
export class SelectPartComponent {
  @Input() data: any;
  isSelected = false;
  displayTableData: any[] = [];
  tableheight = '230px';
  selectData:any;
  searchName:''
  pager = {
    total: 20,
    pageIndex: 1,
    pageSize: 20
  };
  pageSizeOptions = [10, 20, 30, 50, 100];
  dataTableOptions={
    columns:[
      {
          field: 'name',
          header: '',
          fieldType: 'text',
          fixedLeft: '0px'
      },
      {
        field: 'name',
        header: '工序编码',
        fieldType: 'text',
        fixedLeft: '200px'
      },
      {
        field: 'name',
        header: '工单名称',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '状态',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '人员',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '完成进度',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '报工数量',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '生产模式',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '首检',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '末检',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '计划开始时间',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '实际开始时间',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '计划结束时间',
        fieldType: 'text',
      },
      {
        field: 'name',
        header: '实际结束时间',
        fieldType: 'text',
      },

    ]
  }
  tableWidthConfig: TableWidthConfig[] = [
    {
      field:'操作',
      width:'200px'
    },
    {
      field:'工单号',
      width:'150px'
    },
    {
      field:'销售订单号',
      width:'150px'
    },
    {
      field:'销售订单号',
      width:'150px'
    },
    {
      field:'产品编码',
      width:'150px'
    },
    {
      field:'产品名称',
      width:'150px'
    },
    {
      field:'规格',
      width:'150px'
    },
    {
      field:'单位',
      width:'150px'
    },
    {
      field:'计划数量',
      width:'150px'
    },
    {
      field:'已入库数量',
      width:'150px'
    },
    {
      field:'进度',
      width:'150px'
    },
    {
      field:'PlanStartTime',
      width:'150px'
    },
    {
      field:'ActualStartTime',
      width:'150px'
    },
    {
      field:'PlanEndTime',
      width:'150px'
    },
    {
      field:'ActualEndTime',
      width:'150px'
    },

  ];
  partNum: string = null;
  partName: string = null;
  JobOrderNum: string = null;
  JobOrderStatus: string = null;
  JobOrderType: string = null;
  StartDate: string = null;
  EndDate: string = null;
  jobOrderProcesses:any[]=[];
  productJob=[]
  tableData=[];
  checkRows:any[]=[];
  isIconRotated = false;
  @ViewChild(DataTableComponent, { static: true }) datatable: DataTableComponent;
  constructor(private JobOrderService:JobOrderService,private DialogService:DialogService,private StorehouseService:StorehouseService) { }
  ngOnInit(): void {
   this.JobOrderService.GetAllIssueJobOrders(this.pager.pageIndex,this.pager.pageSize).subscribe((data:any)=>{
    this.tableData=data.items
    this.tableData.forEach(item => {
      item.display = false;
    });
    this.pager.total=data.totalCount
  })
  }
  pageIndexChange($event: any) {
    this.search()
  }//切换页码
  pageSizeChange($event: any){
    this.search()
  }//改变每页显示数量
  search(){
    this.JobOrderService.GetJobOrders(this.partNum,this.partName,this.JobOrderNum,this.JobOrderStatus,this.JobOrderType,null,this.StartDate,this.EndDate,this.pager.pageIndex,this.pager.pageSize).subscribe((data:any)=>{
      this.tableData=data.items
      this.pager.total=data.totalCount;
    })
  }
  search2(){
    this.pager.pageIndex=1;
    this.search()
  }
  reset(){
    this.searchName = ''
    this.search()
  }

  toggleRowItem(rowItem: any,rowIndex: number) {
    rowItem.display = !rowItem.display;
  }
  selectPart(item:any, dialogtype?: string){

    const results = this.DialogService.open({
      id: 'dialog-service',
      showAnimation: true,
      width:'1000px',
      title: '工单工序',
      data:{
        pageNumber:1,
        pageSize:20,
        ids:[
          {
            jobOrderId:item.jobOrderId,
            processId:item.processId
          }
        ]
      },
      content: GetPartsComponent,
      dialogtype: dialogtype,
      onClose: () => {

      },
      buttons: [
        {
          cssClass: 'primary',
          text: '确定',
          disabled: false,
          handler: ($event: Event) => {
            this.checkRows=[ results.modalContentInstance.selectData]
            results.modalInstance.hide();
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }
}
